/*
 * Copyright (C) 2004, Velocityme Partnership
 * GroupAccessActions.java
 *
 * Created on 15 September 2004, 04:03
 */

package com.velocityme.www.interfaces;

import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.GroupAccessValue;
import com.velocityme.www.actionforms.GroupAccessActionForm;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author  Robert
 */
public class GroupAccessActions extends DispatchAction {
    
    /** Creates a new instance of GroupAccessActions */
    public GroupAccessActions() {
    }
    
    public ActionForward edit(ActionMapping mapping, 
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        KeySession key = (KeySession)session.getAttribute("sessionKey");
        RemoteClientSession cs = RemoteClientSessionUtil.getHome().create();
        NodePK nodePK = new NodePK((Integer)session.getAttribute("nodeId"));
        if (request.getParameter("btnSubmit").equals("OK")) {
            GroupPK groupPK = new GroupPK(((GroupAccessActionForm)form).getGroupId());
            RolePK rolePK = new RolePK(((GroupAccessActionForm)form).getRoleId());
            cs.groupAccessCreate(key, nodePK, groupPK, rolePK);
        }
        // Cancel simply displays the original node again
        else {
        }
        request.setAttribute("nodePK", nodePK);
        return mapping.findForward("ACTION_SUCCESS");
    }
    
    public ActionForward deleteCheck(ActionMapping mapping, 
                                     ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        session.setAttribute("groupAccessValue", form);
        return mapping.findForward("ACTION_DELETE");
    }
    
    public ActionForward delete(ActionMapping mapping, 
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        if (request.getParameter("btnSubmit").equals("OK")) {
            KeySession key = (KeySession)session.getAttribute("sessionKey");
            RemoteClientSession cs = RemoteClientSessionUtil.getHome().create();
            GroupAccessPK groupAccessPK = new GroupAccessPK(((GroupAccessActionForm)form).getAccessId());
            cs.groupAccessDelete(key, groupAccessPK);
        }
        NodePK nodePK = new NodePK((Integer)session.getAttribute("nodeId"));
        request.setAttribute("nodePK", nodePK);
        return mapping.findForward("ACTION_SUCCESS");
    }
    
}
